<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课程教保指引关联列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>标题：</label>
                            <input type="hidden" name="packageV2Id" th:value="${packageV2Id}"/>
                            <input type="text" name="title"/>
                        </li>

                        <li>
                            <label>类型：</label>
                            <select id="typeName" name="type" class="form-control m-b"
                                    th:with="type=${@dict.getType('course_package_type')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <input type="hidden" id="age" name="age"/>
                            <div id="age_1">
                                <label>月龄：</label>
                                <select id="age_1_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_month')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>

                            <div id="age_2">
                                <label>月龄：</label>
                                <select id="age_2_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_family_month')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>


                            <div id="age_3">
                                <label>月龄：</label>
                                <select id="age_3_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_group_month')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>

                        </li>
                        <li>
                            <input type="hidden" id="face" name="params[face]"/>
                            <div id="type_2_1">
                                <label>面向：</label>
                                <select id="type_2_1_val" name="type_2_1_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_face')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>
                            <div id="type_2_2">
                                <label>面向：</label>
                                <select id="type_2_2_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_family_face')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>
                        </li>

                        <li>
                            <input type="hidden" id="week" name="params[week]"/>
                            <div id="type_1_1">
                                <label>周次：</label>
                                <select id="type_1_1_val" name="type_1_1_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_week')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>


                            <!--                家庭-->
                            <div id="type_1_1_2">
                                <label>周次：</label>
                                <select id="type_1_1_2_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_family_week')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>

                            <!--            群体-->
                            <div id="type_1_1_3">
                                <label>周次：</label>
                                <select id="type_1_1_3_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_group_week')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>

                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="register()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                <i class="fa fa-remove"></i> 删除关联
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:vendorCourseRelPackagev2:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:vendorCourseRelPackagev2:remove')}]];
    var prefix = ctx + "system/vendorCourseRelPackagev2";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "课程教保指引关联",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'vendorCourseId',
                    title: '课程ID'
                },
                {
                    field: 'title',
                    title: '课程标题'
                },
                {
                    field: 'created',
                    title: '创建时间'
                },
                {
                    field: 'createBy',
                    title: '创建账号'
                },
                {
                    field: 'createdName',
                    title: '创建人名'
                },
                {
                    field: 'ageLow',
                    title: '月龄 低限'
                },
                {
                    field: 'ageHigh',
                    title: '月龄 高限'
                },
                {
                    field: 'type',
                    title: '类型名称',
                    formatter: function (value, item, index) {
                        return typeName(item.type);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs  " href="javascript:void(0)" onclick="courseContent(\'' + row.vendorCourseId + '\')"></i>课程详情</a> ');
                        actions.push('<a class="btn btn-warning btn-xs  " href="javascript:void(0)" onclick="courseContentV2(\'' + row.vendorCourseId + '\')"></i>教保指引</a> ');
                        actions.push('<a class="btn btn-danger btn-xs  " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除关联</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
        getType();
    });


    function courseContent(id) {
        var url = '/system/courseContent/courseList?courseId=' + id;
        $.modal.openTab("课程详情", url);
    }

    function courseContentV2(id) {
        var url = '/system/courseContent/courseListV2?courseId=' + id;
        $.modal.openTab("教保指引", url);
    }


    function typeName(type) {
        var content = "";
        if (type == 0) {
            content = '<span class="label label-success">机构端</span>';
        }
        if (type == 1) {
            content = '<span class="label label-primary">家庭端</span>';
        }
        if (type == 2) {
            content = '<span class="label label-warning">小群体课程</span>';
        }
        return content;
    }

    function getType() {
        var type =  $("#typeName").val();
        //机构端
        if (type == 0) {
            $("#type_1_1").attr("style", "display:block;");//显示div
            $("#type_1_2").attr("style", "display:block;");//显示div
            $("#type_2_1").attr("style", "display:block;");//显示div
            $("#age_1").attr("style", "display:block;");//显示div

            $("#type_2_2").attr("style", "display:none;");//隐藏div
            $("#type_1_1_3").attr("style", "display:none;");//隐藏div
            $("#type_1_1_2").attr("style", "display:none;");//隐藏div
            $("#age_2").attr("style", "display:none;");//隐藏div
            $("#age_3").attr("style", "display:none;");//隐藏div
            $("#type_1_1_3_val").val("");//给空值
            $("#typ_1_1_2_val").val("");//给空值
            $("#type_2_2_val").val("");//给空值
            //查询赋值
            $("#age").val($("#age_1_val").val());
            $("#face").val($("#type_2_1_val").val()+"\"");
            $("#week").val($("#type_1_1_val").val()+"\"");
            return true;
        }
        //家庭端
        if (type == 1) {

            $("#type_1_1").attr("style", "display:none;");//隐藏div
            $("#type_1_2").attr("style", "display:none;");//隐藏div
            $("#type_2_1").attr("style", "display:none;");//隐藏div
            $("#type_1_1_3").attr("style", "display:none;");//隐藏div
            $("#age_1").attr("style", "display:none;");//隐藏div
            $("#age_3").attr("style", "display:none;");//隐藏div
            $("#type_1_1_val").val("");//给空值
            $("#type_1_2_val").val("");//给空值
            $("#type_2_1_val").val("");//给空值
            $("#type_2_1_val").val("");//给空值

            $("#type_2_2").attr("style", "display:none;");//隐藏div
            $("#type_2_2_val").val("");//给空值
            $("#type_2_2").attr("style", "display:block;");//显示div
            $("#type_1_1_2").attr("style", "display:block;");//显示div
            $("#age_2").attr("style", "display:block;");//隐藏div

            //查询赋值
            $("#age").val($("#age_2_val").val());
            $("#face").val($("#type_2_2_val").val()+"\"");
            $("#week").val($("#type_1_1_2_val").val()+"\"");
            return true;
        }
        //小群体课
        if (type == 2) {
            $("#type_1_1").attr("style", "display:block;");//显示div
            $("#type_1_2").attr("style", "display:block;");//显示div
            $("#type_1_1_3").attr("style", "display:block;");//显示div
            $("#age_3").attr("style", "display:block;");//显示div

            $("#type_1_1_2").attr("style", "display:none;");//隐藏div
            $("#type_2_1").attr("style", "display:none;");//隐藏div
            $("#type_2_2").attr("style", "display:none;");//隐藏div
            $("#type_1_1").attr("style", "display:none;");//隐藏div
            $("#age_1").attr("style", "display:none;");//隐藏div
            $("#age_2").attr("style", "display:none;");//隐藏div

            $("#type_2_1_val").val("");//给空值

            //查询赋值
            $("#age").val($("#age_2_val").val());
            $("#face").val('');
            $("#week").val($("#type_1_1_3_val").val()+"\"");
            return true;
        }
    }

    $("#typeName").change(function(){
        getType();
    });

    function register() {
        if ( getType()){
            $.table.search();
        }
    }
</script>
</body>
</html>